/**
 * Created by Harvey Zhao on 16-8-27.
 */
import React from 'react'
import { Link, Redirect } from 'react-router'
import TextField from 'material-ui/TextField';
import RaisedButton from 'material-ui/RaisedButton';

export default class Login extends React.Component {
    constructor(props) {
        super(props);

        this.handleChange = this.handleChange.bind(this);
        this.handleClick = this.handleClick.bind(this);

        this.state = {
            username: '',
            password: ''
        }
    }

    handleChange(e) {
        var newState = {};
        newState[e.target.name] = e.target.name === "permanent" ? e.target.checked : e.target.value;
        this.setState(newState);
        this.setState({
            open: false,
        });
    }

    handleClick(e) {
        e.preventDefault();
        var data = {
            username: this.state.username,
            password: this.state.password,
        };
        this.props.login(data);
    };

    render() {
        return (
            <form>
                <TextField
                    hintText="请输入帐号"
                    name="username"
                    value={this.state.username}
                    onChange={ this.handleChange }
                    required
                    />
                <br/>
                <TextField
                    hintText="请输入密码"
                    type="password"
                    name="password"
                    value={this.state.password}
                    onChange={ this.handleChange }
                    required
                    />
                <br/>
                <br/>
                <RaisedButton type="submit" label="登录" primary={true} onClick={ e => this.handleClick(e) }/>
            </form>
        );
    }
}